<template>
  <div>
    <el-dialog :visible.sync="dialogVisible" class="elTable" width="830px" @open="dialogOpen">
      <el-table :data="teacherProfileList">
        <el-table-column property="teaNo" label="教师工号"></el-table-column>
        <el-table-column property="teaName" label="教师姓名"></el-table-column>
        <el-table-column property="teaGender" label="教师性别"></el-table-column>
        <el-table-column property="colName" label="所属学院"></el-table-column>
        <el-table-column property="teaTitle" label="教师职称"></el-table-column>
        <el-table-column label="操作" width="100px">
          <template slot-scope="scope">
            <el-button size="mini" type="danger" plain @click="assign(scope.row.teaNo)">指定教师</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: 'TeacherAssign',
  props: {
    visible: Boolean,
    choNo: String
  },
  data () {
    return {
      dialogVisible: false,
      teacherProfileList: []
    }
  },
  watch: {
    visible () {
      this.dialogVisible = this.visible
    },
    dialogVisible () {
      this.$emit('update:visible', this.dialogVisible)
    }
  },
  methods: {
    listTeacherProfile () {
      this.$axios.get('/api/teacher/profile')
        .then(response => {
          let result = response.data
          if (result.success) {
            this.teacherProfileList = result.data
          } else {
            this.$message.error(result.msg)
          }
        })
    },
    dialogOpen () {
      this.listTeacherProfile()
    },
    assign (teaNo) {
      let comment = {
        choNo: this.choNo,
        teaNo: teaNo
      }
      this.$axios.post('/api/comment', comment)
        .then(response => {
          let result = response.data
          if (result.success) {
            this.$message.success('指定评阅教师成功！')
          } else {
            this.$message.error(result.msg)
          }
        })
    }
  }
}
</script>

<style lang="stylus" scoped>
.elTable >>> .cell {
  text-align: center;
}

.elTable >>> .el-dialog__body {
  padding-top: 10px;
}

.elTable {
  text-align: center;
}
</style>
